using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace EditorExtensions
{
    public class GUIContentAndGUIStyleEx : EditorWindow
    {
        enum Mode
        {
            GUIContent,
            GUIStyle
        }

        private int mToolbarIndex;
        private GUIStyle m_BoxStyle = "box";

        private Lazy<GUIStyle> m_FontStyle = new Lazy<GUIStyle>(() =>
        {
            var retStyle = new GUIStyle("label");
            retStyle.fontSize = 30;
            retStyle.fontStyle = FontStyle.BoldAndItalic;
            retStyle.normal.textColor = Color.green;
            retStyle.hover.textColor = Color.blue;
            retStyle.focused.textColor = Color.red;
            retStyle.active.textColor = Color.cyan;
            retStyle.normal.background = Texture2D.whiteTexture;
            return retStyle;
        });
        
        private Lazy<GUIStyle> m_ButtonStyle = new Lazy<GUIStyle>(() =>
        {
            var retStyle = new GUIStyle(GUI.skin.button);
            retStyle.fontSize = 30;
            retStyle.fontStyle = FontStyle.BoldAndItalic;
            retStyle.normal.textColor = Color.green;
            retStyle.hover.textColor = Color.blue;
            retStyle.focused.textColor = Color.red;
            retStyle.active.textColor = Color.cyan;
            retStyle.normal.background = Texture2D.whiteTexture;
            return retStyle;
        });

        private void OnEnable()
        {

        }

        private void OnGUI()
        {
            [MenuItem("EditorExtensions/02.IMGUI/02.GUIContentAndGUIStyle")]
            static void Open()
            {
                GetWindow<GUIContentAndGUIStyleEx>().Show();
            }

            mToolbarIndex = GUILayout.Toolbar(mToolbarIndex, Enum.GetNames(typeof(Mode)));
            if (mToolbarIndex == (int)Mode.GUIStyle)
            {
                GUILayout.Label("Style of Default");
                GUILayout.Label("Style of box", m_BoxStyle);
                GUILayout.Label("Style of font", m_FontStyle.Value);
                if (GUILayout.Button("Style of button", m_ButtonStyle.Value))
                {
                    Debug.Log("Print Button");                    
                }

            }
            else
            {
                GUILayout.Label("把鼠标放在我身上");
                GUILayout.Label(new GUIContent("把鼠标放在我身上"));
                GUILayout.Label(new GUIContent("把鼠标放在我身上", "放好了"));
                GUILayout.Label(new GUIContent("把鼠标放在我身上", Texture2D.redTexture));
                GUILayout.Label(new GUIContent("把鼠标放在我身上", Texture2D.redTexture, "放好了"));
            }
        }
    }
}